<template>
  <div id="app">
    <router-view></router-view>
  </div>
</template>

<script>
  import { getUserInfo, getCartSum } from './util/request.js'
  export default {
    name: 'App',
    methods: {
      getUser() {
        if (this.$cookie.get('userId')) {
          getUserInfo().then( (res = {}) => {
            this.$store.dispatch('saveUserName', res.username)
          })
        }
      },
      getCartCount() {
        if (this.$cookie.get('userId')) {
          getCartSum().then( (res = 0 ) => {
            this.$store.dispatch('saveCartCount', res)
          })
        }
      }
    },
    mounted() {
      this.getUser()
      this.getCartCount()
    }
  }
</script>

<style lang="scss">
@import './assets/scss/reset.scss';
@import './assets/scss/base.scss';
@import './assets/scss/config.scss';
@import './assets/scss/mixin.scss';
</style>
